package org.example.backend.service.impl;

import jakarta.annotation.Resource;
import org.example.backend.entity.GbLabel;
import org.example.backend.entity.ZxLabel;
import org.example.backend.mapper.LabelMapper;
import org.example.backend.service.LabelService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LabelServiceImpl implements LabelService {
    
    @Resource
    private LabelMapper labelMapper;

    @Override
    public Map<String, Object> getAllLabels() {
        Map<String, Object> result = new HashMap<>();
        
        try {
            // GB标签数据
            Map<String, Object> gbLabels = new HashMap<>();
            gbLabels.put("level1", getGbIndustry1Labels());
            gbLabels.put("level2", getGbIndustry2Labels());
            
            // ZX标签数据
            Map<String, Object> zxLabels = new HashMap<>();
            zxLabels.put("level1", getZxIndustry1Labels());
            zxLabels.put("level2", getZxIndustry2Labels());
            
            result.put("gb", gbLabels);
            result.put("zx", zxLabels);
            
        } catch (Exception e) {
            System.err.println("获取标签数据时发生错误: " + e.getMessage());
            e.printStackTrace();
            // 返回空数据结构
            Map<String, Object> gbLabels = new HashMap<>();
            gbLabels.put("level1", new java.util.ArrayList<>());
            gbLabels.put("level2", new java.util.ArrayList<>());
            Map<String, Object> zxLabels = new HashMap<>();
            zxLabels.put("level1", new java.util.ArrayList<>());
            zxLabels.put("level2", new java.util.ArrayList<>());
            result.put("gb", gbLabels);
            result.put("zx", zxLabels);
        }
        
        return result;
    }

    @Override
    public List<GbLabel> getGbIndustry1Labels() {
        return labelMapper.selectGbIndustry1Labels();
    }

    @Override
    public List<GbLabel> getGbIndustry2Labels() {
        return labelMapper.selectGbIndustry2Labels();
    }

    @Override
    public List<ZxLabel> getZxIndustry1Labels() {
        return labelMapper.selectZxIndustry1Labels();
    }

    @Override
    public List<ZxLabel> getZxIndustry2Labels() {
        return labelMapper.selectZxIndustry2Labels();
    }
}
